<?php

namespace App\Model\Common;

use Illuminate\Support\Facades\Session;

class Group extends Common
{
    protected $sessionGidKey = '';
    protected $Menu = null;
    protected $pidsKey = '';

    public function getPids($opt = [])
    {
        // $gid = session($this->sessionGidKey);
        $gid = Session::get($this->sessionGidKey);
        // dd($gid);
        if (!$gid) {
            return [];
        }
        // $pids = session($this->pidsKey);
        $pids = Session::get($this->pidsKey);

        if (empty($pids) || !empty($opt['no_cache'])) {
            $pids = [];
            if ($gid == 1000) {
                $pids = $this->Menu::where('status', 1)->pluck('id')->toArray();
                //$data = self::where(['status' => 1])->field('id,name,pids')->find();
            } else {
                $data = $this->where(['status' => 1, 'id' => $gid])->select('id','title','pids')->first();
                if ($data['pids']) {
                    $pids = explode(',', $data['pids']);
                }
            }

            // session($this->pidsKey, $pids);
            Session::put($this->pidsKey, $pids);
        }
        
        return $pids;
    }
}
